package services;

import domain.entities.ImportacionDAO;
import domain.entities.Importacion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: vgonzalez
 * Date: 14/09/12
 * Time: 17:01
 * To change this template use File | Settings | File Templates.
 */

@Service
public class ImportacionService implements CRUDService<Importacion>{
    private ImportacionDAO dao;

    public ImportacionService() {
    }

    @Autowired
    public ImportacionService(ImportacionDAO dao) {
        this.dao = dao;
    }


    public void attachDirty(Importacion importacion){
        dao.attachDirty(importacion);
    }

    public Importacion findById(Integer id){
        return dao.findById(id);
    }

    public void save(Importacion importacion){
        dao.save(importacion);
    }

    public <V extends Criteria> List<Importacion> list(V criteria) {
        List<Importacion> list = dao.findAll();
        Iterator<Importacion> it = list.iterator();
        while(it.hasNext()){
            if(!criteria.isIn(it.next())){
                it.remove();
            }
        }
        return list;
    }
}
